<?php
/**
 * 《电话记录》实现类
 *
 * @author 孙晓晔
 * @version $Id: Work.class.php 1035 2010-03-26 05:24:59Z sunxy $
 */
require_once(dirname(__FILE__) . '/../tel/Cdr.class.php');

class CdrDg extends Cdr {
	public $in_out = array(
		'-' => '请选择',
		'1' => '呼入',
		'2' => '呼出',		
	);

	function __construct() {
		$request['update'] = '$Date: 2009/02/16 07:36:07 $';
		$request['revision'] = '$Revision: 1.1 $';

		parent::__construct($request);
	}
	
	function bb($controller, $request) {
	
		require_once(dirname(__FILE__) . '/ChargeQx.class.php');
		$aa = new ChargeQx();
	
		$dd = date('Y-m-d', strtotime('-3 day'));
	
		$db = newdb('cdr');
		$fmt = "SELECT * FROM %s WHERE cost is NULL ORDER BY calldate DESC";
		$fmt = "SELECT * FROM %s WHERE calldate > '%s' AND cost is NULL ORDER BY calldate DESC";
		// $fmt = "SELECT * FROM %s WHERE calldate > '%s' AND cost is NULL ORDER BY calldate DESC LIMIT 5";
		$sql = sprintf($fmt, $this->tbl, $dd);
		echo $sql . "\n";
		$result = $db->query($sql);
		while ($row = $db->fetch_array($result)) {
			$cost = $aa->_cost($row['channel'], $row['dst'], $row['billsec'], $row['calldate']);
	
			$fmt = "UPDATE %s SET cost = '%s' WHERE id = '%s'";
			$sql = sprintf($fmt, $this->tbl, $cost, $row['id']);
			echo $sql . "\n";
			$db->query($sql);
		}
	
		logdate($controller, $request);
		return true;
	}

}
?>